//工具模块
//1.querystring 查询字符串
const querystring = require('querystring');
var str = 'name=tom&age=20&sex=1';
//转成对象
//console.log(querystring.parse(str));

var obj = {lid: 2, pname: 'dell'};
//转成字符串
//console.log(querystring.stringify(obj));
//2. url模块
const url = require('url');
var urlStr = 'http://www.tmooc.cn/course/web/detail/index.html?pno=2&name=nodejs#second';
//使用url模块进行解析
var result = url.parse(urlStr);
var queryStr = result.query;
//把result.query，转成对象
var result2 = querystring.parse(queryStr);
console.log(result2);
//把对象转换url
var obj = {
  protocol: 'http:',
  port: 8080,
  hostname: 'www.codeboy.com',
  search: '?pno=2&name=nodejs',
  pathname: '/product/list.html'
}
var result3 = url.format(obj);
console.log(result3);




